<?php
declare(strict_types=1);

namespace app\model;

class Menu extends BaseModel
{
    // 设置表名
    protected $name = 'menu';

    // 设置字段信息
    protected $schema = [
        'id'          => 'int',
        'parent_id'   => 'int',
        'menu_name'   => 'string',
        'menu_type'   => 'int',
        'menu_url'    => 'string',
        'menu_icon'   => 'string',
        'menu_order'  => 'int',
        'status'      => 'int',
        'create_time' => 'datetime',
        'update_time' => 'datetime'
    ];

    // 关联角色
    public function roles()
    {
        return $this->belongsToMany(Role::class, 'role_menu');
    }

    // 获取子菜单
    public function children()
    {
        return $this->hasMany(self::class, 'parent_id');
    }
} 